<?php
    /**
    * Phục vụ cho việc cache dữ liệu
    */
    class CacheData extends CApplicationComponent
    {
        public function init(){
            parent::init();
            if(!empty(Yii::app()->cache->cachePath))    Myext::createDir(Yii::app()->cache->cachePath);
        }

        private $_cities;
        public function getCityDataAll($refresh = false, $expire = 0){
            $key = __CLASS__.__FUNCTION__;
            if($refresh){
                Yii::app()->cache->delete($key);
                $this->_cities = null;      
            }

            if($this->_cities)    return $this->_cities;

            $this->_cities = Yii::app()->cache->get($key);
            if($this->_cities === false){
                $this->_cities = City::model()->getDataAll(false);
                Yii::app()->cache->set($key, $this->_cities, $expire);
            }
            return $this->_cities;
        }


        private $_cats;
        public function getCatDataAll($refresh = false, $expire = 0){
            $key = __CLASS__.__FUNCTION__;
            if($refresh){
                Yii::app()->cache->delete($key);
                $this->_cats = null;      
            }        

            if($this->_cats)    return $this->_cats;

            $this->_cats = Yii::app()->cache->get($key);
            if($this->_cats === false){
                $this->_cats = PostCat::model()->getDataAll(false);
                Yii::app()->cache->set($key, $this->_cats, $expire);
            }
            return $this->_cats;
        }




    }
